package com.study.leetcode;

public class Solution_560 {
    public int subarraySum(int[] nums, int k) {
        int len = nums.length;
        int[] pre = new int[len + 1];
        pre[0] = 0;
        for (int i = 0; i < len; i++) {
            pre[i + 1] = pre[i] + nums[i];
        }
        int count = 0;
        for (int left = 0; left < len; left++) {
            for (int right = left + 1; right <= len; right++) {
                if (pre[right] - pre[left] == k) {
                    count++;
                }
            }
        }
        return count;
    }
}
